package com.fanfanwang.ffw.app.asynctask;

import java.util.ArrayList;
import java.util.LinkedHashMap;

import org.json.JSONException;

import android.app.Activity;
import android.text.TextUtils;

import com.fanfanwang.ffw.app.bean.CarportBean;
import com.fanfanwang.ffw.app.bean.ParkNumBean;
import com.fanfanwang.ffw.app.bean.SucParkNumBean;
import com.fanfanwang.ffw.app.common.Md5Util;
import com.fanfanwang.ffw.app.common.ToastAlone;
import com.fanfanwang.ffw.app.fragment.GlyHomeFragment;
import com.fanfanwang.ffw.app.net.HttpRequest.HttpRequestException;
import com.fanfanwang.ffw.app.net.IssAsyncTask;
import com.fanfanwang.ffw.app.net.IssNetLib;
import com.fanfanwang.ffw.app.net.WebServiceHelper;
import com.fanfanwang.ffw.app.tenant.R;
import com.fanfanwang.ffw.app.ui.my.GlyMyCarportManagementAct;



public class GetParknumListAsyncTask extends IssAsyncTask<String, String, SucParkNumBean> {
	private Activity mActivity;
	private String park_userid;
	public GetParknumListAsyncTask(Activity activity,String park_userid) {
		super(activity);
		mActivity = activity;
		this.park_userid = park_userid;
	}

	@Override
	protected SucParkNumBean doInBackground(String... params) {
		// TODO 	addAuctionPrice($apiusername,$apipassword,$userid,$pid,$price)
		SucParkNumBean sucParkNumBean = null;
		LinkedHashMap<String, Object> paramsMap = new LinkedHashMap<String, Object>();
		paramsMap.put("apiusername", "parking");
		paramsMap.put("apipassword", Md5Util.getMD5To32("parking"));
		paramsMap.put("park_userid", park_userid);
		try {
			sucParkNumBean = IssNetLib.getInstance(mActivity).getParknumList(WebServiceHelper._GETPARKNUMLIST, paramsMap);
			//TODO 手动赋值 ，接口报buffered is not closed 异常
//			{"status":1,"data":[{"id":"1","park_num":"01","status":"0,"type":"0"}]}

		} catch (HttpRequestException e) {
			e.printStackTrace();
			//			exception = getResources().getString(R.string.e_net_error);
		} catch (Exception e) {
			e.printStackTrace();
			//			exception = getResources().getString(R.string.e_json);
		}
		return sucParkNumBean;
	}

	@Override
	protected void onPostExecute(SucParkNumBean result) {
		super.onPostExecute(result);
		if (exception != null) {
			ToastAlone.showToast(mActivity, exception);
			return;
		}
		if (result != null) {
			if (result.status == 1) {

				if(result.data != null){
					if(GlyHomeFragment.iGetParknumList!=null){
					GlyHomeFragment.iGetParknumList.getParknumList(result.data);
					}if(GlyMyCarportManagementAct.iGetParknumList!=null)
					{
						GlyMyCarportManagementAct.iGetParknumList.getParknumList(result.data);
					}
				}
			}else if(result.status == 0){
				if (result.msg != null && !TextUtils.isEmpty(result.msg)) {
					ToastAlone.showToast(mActivity,com.fanfanwang.ffw.app.AppConstant.URLDecoderString(result.msg));
				} else {
					ToastAlone.showToast(mActivity,mActivity.getResources().getString(R.string.e_net_error));
				}
			}
		}
	}
}
